<?php
	error_reporting(E_ALL & ~E_NOTICE);
	session_start();
    include('conn.php');
		
	$trndate=date("Y-m-d", strtotime($_REQUEST['dt']));	
	$bid=$_REQUEST['bid'];	
	$custid=$_REQUEST['custid'];	
    $venid1=$_REQUEST['venid1'];
    $venid2=$_REQUEST['venid2'];
    $venid3=$_REQUEST['venid3'];
	$debitamt=$_REQUEST['dramount'];
	$creditamt=$_REQUEST['cramount'];
	$netrate1=$_REQUEST['netrate1'];	
	$netrate2=$_REQUEST['netrate2'];	
	$netrate3=$_REQUEST['netrate3'];	
	$remarks=$_REQUEST['remarks'];
	$payid=$_REQUEST['payid'];
	$pd=$_REQUEST['paydate'];
	$pdlen = strlen($pd);
	$bankid=$_REQUEST['bankid'];
	$branchname=$_REQUEST['branch'];	
	$enteredby=$_SESSION['username'];
	$id1=$_REQUEST['IDNumber1'];
	$id2=$_REQUEST['IDNumber2'];
	$id3=$_REQUEST['IDNumber3'];
	$rev1=$_REQUEST['rev1'];
	$rev2=$_REQUEST['rev2'];
	$rev3=$_REQUEST['rev3'];
	$custid=str_replace('c',"",$custid);
	$custid=str_replace('d',"",$custid);
	$custid=str_replace('i',"",$custid);
	$custid=str_replace('r',"",$custid);
    $custid=str_replace('v',"",$custid);
	//$idnumber=$_REQUEST['idnumber'];
	
		 if ($bankid==0)
		 $bankid=1;
		 if($payid==0)
		 $payid=8;

		 if($_SESSION["usertype"]==1)		 
			$status=0;		 
		 else		 
			$status=-1;		 		 
			
		
		$sql="insert into transactionmast (trndate,bid,custid,venid,venid2,venid3,debitamt,creditamt,netrate,netrate2,netrate3,remarks,payid,bankid,branchname,paydate,payamt,enteredby,entrydt,status,catid,subid,IDNumber,IDNumber2,IDNumber3)		
		values('".$trndate."','".$bid."','".$custid."','".$venid1."','".$venid2."','".$venid3."','".$debitamt."','".$creditamt."','".$netrate1."','".$netrate2."','".$netrate3."','".$remarks."','".$payid."','".$bankid."','".$branchname."',case when $pdlen > 2 then '".date("Y-m-d", strtotime($pd))."' else NULL end,'".$payamt."','".$enteredby."',sysdate(),".$status.",'1','1','".$id1."','".$id2."','".$id3."');";
		
		$res=mysql_query($sql);
		echo $sql;			
		if($res)		
			$msg='Record saved successfully!';		
		else		
			$msg='Record not saved successfully';					
	echo $msg."<br><br>";
	
	if($rev1 == "true")
	{
		$today = date("Y-m-d");     
		$sql2="insert into transactionmast (trndate,bid,custid,venid,venid2,venid3,debitamt,creditamt,netrate,netrate2,netrate3,remarks,payid,bankid,branchname,paydate,payamt,enteredby,entrydt,status,catid,subid,IDNumber)
		values('".$trndate."','15','".$venid1."','0','0','0','0','".$netrate1."','0','0','0','".$remarks."','".$payid."','".$bankid."','".$branchname."','".$today."','".$payamt."','".$enteredby."',sysdate(),".$status.",'1','1','".$id1."');";
		$res2=mysql_query($sql2);
		echo $sql2;			
		if($res2)		
			$msg='rev1 Record saved successfully!';		
		else		
			$msg='rev1 Record not saved successfully';
		echo $msg."<br><br>";
	}
	if($rev2 == "true")
	{
		$today = date("Y-m-d");     
		$sql2="insert into transactionmast (trndate,bid,custid,venid,venid2,venid3,debitamt,creditamt,netrate,netrate2,netrate3,remarks,payid,bankid,branchname,paydate,payamt,enteredby,entrydt,status,catid,subid,IDNumber)
		values('".$trndate."','15','".$venid2."','0','0','0','0','".$netrate2."','0','0','0','".$remarks."','".$payid."','".$bankid."','".$branchname."','".$today."','".$payamt."','".$enteredby."',sysdate(),".$status.",'1','1','".$id2."');";
		$res2=mysql_query($sql2);
		echo $sql2;			
		if($res2)		
			$msg='rev2 Record saved successfully!';		
		else		
			$msg='rev2 Record not saved successfully';
		echo $msg."<br><br>";
	}
	if($rev3 == "true")
	{
		$today = date("Y-m-d");     
		$sql2="insert into transactionmast (trndate,bid,custid,venid,venid2,venid3,debitamt,creditamt,netrate,netrate2,netrate3,remarks,payid,bankid,branchname,paydate,payamt,enteredby,entrydt,status,catid,subid,IDNumber)
		values('".$trndate."','15','".$venid3."','0','0','0','0','".$netrate3."','0','0','0','".$remarks."','".$payid."','".$bankid."','".$branchname."','".$today."','".$payamt."','".$enteredby."',sysdate(),".$status.",'1','1','".$id3."');";
		$res2=mysql_query($sql2);
		echo $sql2;			
		if($res2)		
			$msg='rev3 Record saved successfully!';		
		else		
			$msg='rev3 Record not saved successfully';
		echo $msg."<br><br>";
	}
?>